<?php
namespace Common\Library;

/**
 * 新闻分类对象工厂
 * Class CompanyModel
 * @package Common\Library
 */
class NewsClassifyDao {

    /**
     * 通过ID获取新闻分类
     * @param int $id
     * @return NewsClassifyModel
     */
    public static function FetchByID($id){
        $companyModel = D('newsclassify');
        $data = $companyModel->where(['nc_id'=>$id])->select();
        $modal = new NewsClassifyModel();
        $modal->id = $data[0]['nc_id'];
        $modal->name = $data[0]['nc_name'];
        $modal->detail = $data[0]['nc_detail'];
        $modal->sid = $data[0]['si_id'];
        return $modal;
    }

    /**
     * 更新数据
     * @param NewsClassifyModel $classify
     */
    public static function Save(NewsClassifyModel $classify){
        $result = D('newsclassify');
        $data['nc_name']    = $classify->name;
        //$data['nc_english'] = I('post.nc_english');
        $data['nc_detail']  = $classify->detail;
        $result->where(['nc_id' => $classify->id])->save($data);
    }

    /**
     * @param NewsClassifyModel $classify
     * @param SiteModel $site
     */
    public static function Create(NewsClassifyModel $classify, SiteModel $site){
        $result = D('newsclassify');
        $data['nc_name']    = $classify->name;
        //$data['nc_english'] = I('post.nc_english');
        $data['nc_detail']  = $classify->detail;
        $data['si_id'] = $site->id;
        $result->data($data)->add();
    }



}